const KeySet = ['Token', 'UserInfo'];
const storage = {
    getToken: () => {
      return localStorage.getItem('Token');
    },
    getUserInfo: () => {
      return localStorage.getItem('UserInfo');
    },
    getUserInfoObject: () => {
      return JSON.parse(localStorage.getItem('userInfo') || '');
    },
    
    setToken: (value: string) => {
      localStorage.setItem('Token', value);
    },
    setUserInfo: (value: string | Record<string, unknown>) => {
      let valueStr = typeof value !== 'string' ? JSON.stringify(value) : value;
      localStorage.setItem('UserInfo', valueStr);
    },
    setItems: (pairs: Record<string, string>) => {
      Object.entries(pairs).forEach(([key, value]) => {
        localStorage.setItem(key, value);
      });
    },
    removeAll: () => {
      KeySet.forEach((x) => {
        localStorage.removeItem(x);
      });
    },
  };
  export default storage;